<template>
  <div>
    <div class="navCon">
      <ul>
        <li v-for="(item,index) in txtList" :key="index"  
        ref="li">
          <div class="nav">
            <div class="nav_day animate__animated animate__animated">
              <span>{{ item.date }}</span>
            </div>
        
            <div class="nav_date">
              <span>星期{{ item.day }}</span>
              <span>冬月{{ item.month }}</span>
            </div>
            <div class="more">
              <div class="circle"></div>
              <div class="line"></div>
              <router-link to="/calendar">
                  <span>点击阅读更多</span>
              </router-link>
            </div>
          </div>
          <div class="cardList" 
          v-on:click="handleClick(item.title,item.content)">
            <!-- <div class="font_card"></div> -->
            <div class="knowCard">
              <div class="title">
                <span>{{ item.title }}</span>
              </div>
              <div class="article">
                <p>
                  {{ item.content }}
                </p>
              </div>
              <div class="comments">
                <div class="idea">
                  <span>{{ item.like }} 喜欢 · {{ item.idea }} 想法</span>
                </div>
                <div class="read">
                    <span class="noread" v-if="!isRead">阅读</span>
                    <span class="beread" v-if="isRead">已读</span>
                </div>
              </div>
            </div>
            <!-- <div class="bethind_card"></div> -->
          </div>
        </li>
        <li>
          <div class="nav">
            <div class="nav_day">
              <span>18</span>
            </div>
        
            <div class="nav_date">
              <span>星期三</span>
              <span>冬月十九</span>
            </div>
          </div>
          <div class="cardList">
            <div class="font_card"></div>
            <div class="knowCard">
               <div class="content">
                  <p>没有更多数据了~</p>
               </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <!-- 点击改变 -->
    <div class="con_icon">
      <div class="left_row f_left" v-on:click="slideLt">
        <i class="iconfont icon-arrowLeft-fill"></i>
      </div>
      <div class="right_row f_right" v-on:click="slideRh" v-if="isShow">
        <i class="iconfont icon-arrowRight" ></i>
      </div>
    </div>
    <!-- <div class="swiper mySwiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div>
        <div class="swiper-slide">Slide 4</div>
        <div class="swiper-slide">Slide 5</div>
        <div class="swiper-slide">Slide 6</div>
        <div class="swiper-slide">Slide 7</div>
        <div class="swiper-slide">Slide 8</div>
        <div class="swiper-slide">Slide 9</div>
      </div>
      <div class="swiper-pagination"></div>
    </div> -->
    
  </div>
</template>

<script>
import detail from "@/datajson/shouye.json";
import Swiper from "@/assets/js/swiper-3.4.2.min.js";
// import Swiper from "swiper";

export default {
  data() {
    return {
      txtList: [],
      arr: detail,
      count: 0,
      width: 380,
      time: null,
      isShow: true,
      isRead: "",
    };
  },
  methods: {
    slideData() {
      let res = this.arr.result;
      // console.log(res,"res");
      this.txtList = res;
      // console.log(this.txtList);
    },
    //向左点击
    slideLt() {
      //获取li元素
      let li = document.querySelector("li");
      // console.log(this.$refs.li);
      li.style.marginLeft = `0px`;
      this.slideData();
    },
    //向右点击
    slideRh() {
      //获取li元素
      let li = document.querySelector("li");
      // console.log(this.$refs.li);
      ++this.count;
      li.style.marginLeft = `-${this.width * this.count}px`;

      if (this.count > 9) {
        this.count = 9;
        this.isShow = false;
      }
      this.slideData();
    },
    // 点击跳转
    handleClick(title, content) {
      this.$router.push({
        path: "/article",
        name: "article",
        params: { title: title, content: content },
      });
      //本地存储
      let obj = {};
      obj.title = title;
      obj.content = content;
      localStorage.setItem("obj", JSON.stringify(obj));
    },
  },
  created() {
    this.slideData();
    // this.isRead = sessionStorage.getItem('isRead');
  },
  mounted() {
    new Swiper(".mySwiperr", {
      slidesPerView: 4,
      spaceBetween: 30,
      centeredSlides: true,
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
    });
  },
};
</script>

<style lang="scss" scoped>
@import "../assets/css/reset.css";
@import "../assets/css/swiper-3.4.2.min";
// @import "swiper/dist/css/swiper.css";
.swiper {
  width: 375px;
  height: 600px;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}

ul {
  display: flex;
  overflow: hidden;
  width: 3800px;
  li {
    width: 380px;
    display: block;
  }
}
.nav {
  width: 380px;
  height: 90px;
  div {
    float: left;
  }
  .nav_day {
    height: 90px;
    line-height: 90px;
    font-size: 50px;
    padding-left: 20px;
    color: #f0f0f0;
  }
  .nav_date {
    height: 90px;
    padding-top: 20px;
    padding-left: 20px;
    font-size: 18px;
    color: #808080;
    span {
      display: block;
    }
  }
  .more {
    margin-top: 10px;
    .circle {
      width: 12px;
      height: 12px;
      margin-top: 10px;
      background: #c39f65;
      border-radius: 50%;
    }
    .line {
      width: 38px;
      height: 2px;
      margin-top: 15px;
      background: #c39f65;
    }
    span {
      display: inline-block;
      font-size: 18px;
      color: #c39f65;
      margin-top: 5px;
      padding-left: 2px;
    }
  }
}
// 卡片
.cardList {
  width: 100%;
  display: flex;
}
.font_card {
  width: 20px;
  height: 450px;
  background: #fff;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}
.bethind_card {
  width: 20px;
  height: 450px;
  background: #fff;
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}
// 知识卡片
.knowCard {
  width: 85%;
  height: 460px;
  margin: 0 auto;
  border-radius: 10px;
  background: #fff;
  .title {
    height: 220px;
    font-size: 30px;
    span {
      float: right;
      padding-top: 20px;
      letter-spacing: 6px;
      writing-mode: vertical-lr;
      margin-right: 20px;
    }
  }
  .article {
    height: 170px;
    font-size: 18px;
    padding-left: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 18px;
    padding-right: 18px;
  }
  .comments {
    display: flex;
    color: #808080;
    font-size: 16px;
    div {
      flex-grow: 1;
    }
    .idea {
      line-height: 50px;
      padding-left: 18px;
    }
    .read {
      span {
        display: inline-block;
        width: 60px;
        height: 30px;
        line-height: 30px;
        border-radius: 20px;
        text-align: center;
        margin-top: 10px;
        margin-right: -10px;
      }
      .noread {
        color: #fff;
        background: #ffa631;
      }
      .beread {
        color: #808080;
        background-color: #ccc;
      }
    }
  }
  .content {
    text-align: center;
    line-height: 450px;
    color: #808080;
  }
}
// 左右箭头
.con_icon {
  position: absolute;
  width: 100%;
  height: 50px;
  bottom: 50px;
  div {
    width: 50px;
    line-height: 30px;
    text-align: center;
    i {
      font-size: 22px;
      color: #808080;
    }
  }
}
</style>